#ifndef _TH_NAND_H
#define _TH_NAND_H

#include <types.h>

/* Select the chip by setting nCE to low */
#define NAND_NCE        0x01
/* Select the command latch by setting CLE to high */
#define NAND_CLE        0x02
/* Select the address latch by setting ALE to high */
#define NAND_ALE        0x04

#define NAND_CTRL_CLE       (NAND_NCE | NAND_CLE)
#define NAND_CTRL_ALE       (NAND_NCE | NAND_ALE)
#define NAND_CTRL_CHANGE    0x80

/*
 * Standard NAND flash commands
 */
#define NAND_CMD_READ0      0
#define NAND_CMD_READ1      1
#define NAND_CMD_READOOB    0x50
#define NAND_CMD_STATUS     0x70
#define NAND_CMD_READID     0x90
#define NAND_CMD_ERASE1		0x60
#define NAND_CMD_SEQIN		0x80
#define NAND_CMD_NONE       -1

void nand_init(void);
void nand_read_id(uint8_t *id, uint8_t *len);
void nand_command(uint32_t cmd, int32_t column, int32_t page_addr);
uint32_t nand_is_bad_block(uint32_t block);
void nand_read_page(uint32_t block, uint32_t page, uint8_t *dst);
uint32_t nand_read(uint32_t offset, uint32_t length, uint8_t *buffer);

#endif /* _TH_NAND_H */
